//验证的构造器
class FiledValidator {
    constructor(txtId, validateFn) {
        this.input = $(`#${txtId}`);
        this.p = this.input.nextElementSibling;
        this.validateFn = validateFn;
        this.input.onblur = () => {
            this.validate();
        }
    }

    //验证
    async validate() {
        const err = await this.validateFn(this.input.value);
        if (err) {
            this.p.innerText = err;
            return false
        } else {
            this.p.innerText = '';
            return true;
        }
    }

    static async validate(...validators) {
        console.log('a')
        const proms = validators.map((v) => v.validate());
        const result = await Promise.all(proms);
        return result.every(r => r);
    }
}